<div class="SipeiMain_r fr">
    <h2 class="clearfix fonts_18 height45 fontc_444"><?php echo $this->title; ?></h2>
    <div class="clearfix back_bgf border_c mt15 pt20 pb20">
        <div class="clearfix pb20 pl30">
            <input type="button" value="新增" onclick="addrulesdetail(<?php echo $pb_id; ?>)" style="margin-right:30px;" class="fr b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 mr10 cursor" />
        	<input type="button" value="删除" onclick="delete_all()" class="fl b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
        </div>
        <table class="height40" width="100%">
            <thead class="back_bgf5 fontc_666">
                <tr>
                    <th width="40" align="right" class="m_hr_t m_hr_b pr10"><input type="checkbox" class="checkboxs"></th>
                    <th width="90" align="center" class="m_hr_t m_hr_b">序号</th>
                    <th width="200" align="center" class="m_hr_t m_hr_b">导出栏位名称</th>
                    <th width="170" align="center" class="m_hr_t m_hr_b pr10 pl10">导出数据</th>
                    <th width="170" align="center" class="m_hr_t m_hr_b">固定值</th>
                    <th width="100" align="center" class="m_hr_t m_hr_b">操作</th>
                </tr>
            </thead>
            <tbody class="fontc_444">
                <?php if (!empty($rulesdetail)): ?>
                    <?php
                    foreach ($rulesdetail as $key => $one):
                        ?>
                        <tr>
                            <td align="right" class="m_hr_b pr10"><input type="checkbox" name="deleteAll[]" value="<?php echo $one['id'];?>" class="checkbox"></td>
                            <td align="center" class="m_hr_b"><?php if (!empty($one['number'])){ echo $one['number'];}else {echo '';} ?></td>
                            <td align="center" class="m_hr_b"><?php echo $one['name']; ?></td>
                            <td align="center" class="m_hr_b pr10 pl10">
                            <?php 
                            if ($one['out_name']=='gdz'){
                            	echo '固定值';
                            }else {
                            	$problemrule = new Problemrule();
                            	$problemruleinfo = $problemrule->findByPk($one['problemrule_id']);
                            	if(!empty($problemruleinfo)){
                            		$Problemruleinfo = $problemrule->findByPk($one['problemrule_id'])->attributes;
                            		$tableinfo = Import::_gettableinfo($Problemruleinfo['sqlname']);
                            		foreach ($tableinfo as $t=>$f){
                            			if ($f['COLUMN_NAME']==$one['out_name']){ echo $f['COMMENTS']; }
                            		}
                            	}
                            }
							?></td>
                            <td align="center" class="m_hr_b"><?php echo $one['value']; ?></td>
                            <td align="center" class="m_hr_b">
                                <a href="javascript:;" onclick="editrulesdetail(<?php echo $one['id']; ?>)" class="mr10" title="编辑">
                                    <img src="/themes/default/images/Sipei/edit.png" />
                                </a>
                                <a href="javascript:;" onclick="deleteruledetail(<?php echo $one['id']; ?>, $(this))" title="删除"><img src="/themes/default/images/Sipei/delate.png" /></a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr><td colspan="7" align="center" class="m_hr_b">暂时没有用户数据</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
        <?php $this->renderPartial('//partial/partial_pager', array('pages' => $pages, "url" => $pageUrl)); ?>
    </div>
</div>
<script>
function editrulesdetail(id) {
	api = $.dialog({
		id: 'testID2',
		lock: true,
		fixed: true,
		title: "编辑",
		width: 500,
		height: 300,
		max: false,
		min: false
	});
	$.get('/problem/rules/addrulesdetail', {id: id}, function(html) {
		api.content(html);
	});
}
function deleteruledetail(id, $this) {
	$.dialog.confirm('确定删除吗', function() {
		$.get('/problem/rules/deleteruledetail', {id: id}, function(data) {
			if (data == 1) {
				$this.parents("tr").remove();
			} else {
				alert("删除失败");
			}
		});
	});
}
function delete_all(){
	var aa='';
	$("input[name='deleteAll[]']:checkbox:checked").each(function(){
		aa+=$(this).val()+',';
	});
	if(aa == ''){
		$.dialog.alert("请选择要删除条目");
		return false;
	}
	$.dialog.confirm('确定删除所选数据吗', function() {
		aa+=0;

		$.get('/problem/rules/delete_d_all', {id: aa}, function(data) {
			location.reload();

		});
	});
}
function addrulesdetail(pb_id) {
	api = $.dialog({
		id: 'testID2',
		lock: true,
		fixed: true,
		title: "新增",
		width: 500,
		height: 300,
		max: false,
		min: false
	});
	$.get('/problem/rules/addrulesdetail', {pb_id: pb_id}, function(html) {
		api.content(html);
	});
}
$(function() {
	$(".checkboxs").click(function() {
		var checkedS = $(this).attr("checked");
		if (checkedS) {
			$(".checkbox").attr("checked", true)
		} else {
			$(".checkbox").removeAttr("checked")
		}
	})

})
</script>